package org.itzheng.yuezhi.utils;

import android.content.Context;
import android.content.SharedPreferences;

import org.itzheng.yuezhi.App;

/**
 * Title:SharedPreferences的操作工具类<br>
 * Description: <br>
 * Company: <br>
 *
 * @author ZhengYongdong
 * @email ItZheng@ZoHo.com
 * @date 2016/6/25 0025
 */
public class MySP {
    private final static String PREF_NAME = "yuezhi";
    private static SharedPreferences prefs;
    private static SharedPreferences.Editor editor;

    public MySP() {
        if (prefs == null) {
            prefs = App.application.getSharedPreferences(PREF_NAME, Context.MODE_PRIVATE);
        }
        if (editor == null) {
            editor = prefs.edit();
        }
    }

    public static MySP getInstance() {
        return new MySP();
    }

    /**
     * @param key
     * @param value
     * @return 是否保存成功
     */
    public boolean putBoolean(String key, boolean value) {
        return editor.putBoolean(key, value).commit();
    }

    public boolean getBoolean(String key, boolean defValue) {
        return prefs.getBoolean(key, defValue);
    }

    public boolean putString(String key, String value) {
        return editor.putString(key, value).commit();
    }

    public String getString(String key, String defValue) {
        return prefs.getString(key, defValue);
    }
}
